<?php
    session_start();
?>
<!-- InstanceBegin template="/Templates/admin_template.dwt.php" codeOutsideHTMLIsLocked="false" --><?php
	include("../Connect/connection.php")
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Admin page</title>

<!-- CSS -->
<link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]-->

<!-- JavaScripts-->
<script type="text/javascript" src="style/js/jquery.js"></script>
<script type="text/javascript" src="style/js/jNice.js"></script>
<script src="datetimepicker_css.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<div id="wrapper">
    	<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
    	        
        <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet -->
        <ul id="mainNav">
        	<li><a href="#" class="active">ADMIN</a></li> <!-- Use the "active" class for the active menu item  -->
        	
        	<li class="logout"><a href="login.php">LOGOUT</a></li>
        </ul>
        <!-- // #end mainNav -->
        <div id="containerHolder">
			<div id="container">
       		  <div id="sidebar">
                	<ul class="sideNav">
                    	<li><a href="listnews.php">List News</a></li>
                    	<li><a href="addnews.php">Add News</a></li>
                    	<li><a href="listcar.php">List Cars</a></li>
                    	<li><a href="addcar.php">Add Cars</a></li>
                    	<li><a href="listcompany.php">List Companies</a></li>
                    	<li><a href="addcompany.php">Add Companies</a></li>
                    	<li><a href="listorder.php">Oders</a></li>
                    	<li><a href="listordersubmit.php">Oders submit</a></li>
                    	<li><a href="listcustomer.php">Customers</a></li>
                    </ul>
                    <!-- // .sideNav -->
                </div>    
                <!-- // #sidebar -->
                
                <!-- h2 stays for breadcrumbs -->
                <!-- InstanceBeginEditable name="EditRegion2" -->
                <div id="main">
                <?php
                        if (!isset($_SESSION["AdminID"])){
                            echo("<script>alert('Login, please !');</script>");
                            echo("<script>window.location='login.php';</script>");
                        }else{
                            if($_SESSION["AdminID"] == ''){
                                echo("<script>alert('Dang Nhap, please !');</script>");
                                echo("<script>window.location='login.php';</script>");
                            }
              			}
                    ?>
                <form action="" method="post" enctype="multipart/form-data" name="formupload" id="formupload">
                	<?php
					if(isset($_REQUEST["id"])){
						$id = $_REQUEST["id"];
						$query = mysql_query("select * from cars where CarID=$id");
						while($rs=mysql_fetch_array($query)){
							$title=$rs['Name'];
							$sub=$rs['Sumary'];
							$content=$rs['Content'];
							$status==$rs['Status'];
							$image=$rs['Image'];
							$time=$rs['TimeProduction'];
							$comid=$rs['ComID'];
							?>
                            
                            <table width="100%" border="1">
                              <tr>
                                <td width="120">Name</td>
                                <td><input name="txtTitle" type="text" style="width:550px" value="<?= $title ?>" /></td>
                              </tr>
                              <tr>
                                <td width="120" align="left" valign="top">Submary</td>
                                <td>
                                <textarea name="txtSubmary" style="width:550px;height:100px" ><?= $sub ?></textarea>
                                </td>
                              </tr>
                              <tr>
                              <td></td> <td><img style="width:100px" src="../images/<?=$image ?> " /></td>
                              </tr>
                              <tr>
                                <td>Image</td>
                                <td>
                                  <input name="file" type="file" id="file" size="20"/>
                                  
                                  </td>
                                
                              </tr>
                              <tr>
                                <td width="120" align="left" valign="top"></td>
                                <td><textarea name="txtContent"  style="width:550px; height:500px;" ><?=$content ?></textarea></td>
                              </tr>
                              <tr>
                                <td width="120" align="left" valign="top">Date prodution</td>
                                <td>
                                        <input type="text" name="date" id="demo1" maxlength="25" size="25" value="<?=$time ?>"/>
                                        <img src="images2/cal.gif" onClick="javascript:NewCssCal('demo1')" style="cursor:pointer"/>
                                    
                                </td>
                              </tr>
                              <tr>
                                <td align="left">Company</td>
                                <td>
									 <select name="company" style="width: 200px;">
                                     <option value="0">Select company</option>
                                 <?php
								 	$resultCom = mysql_query("SELECT * FROM company"); 
									 while($rowCom = mysql_fetch_assoc($resultCom)) 
									 { 
									 $com_id = $rowCom["ComID"];
									 $com_name = $rowCom["Name"];
									 ?>
										  <option <?php if($comid==$com_id){ ?> selected="selected" <?php } ?>  value="<?=$com_id;?>"><?=$com_name;?></option>
                                          <?php
									 }
								 ?>
									 </select>
                                 </td>
                              </tr>
                              <tr>
                                <td align="left"></td>
                                <td>
                                  <input type="submit" name="btnSave"  id="btnSave" value="Save" />
                                  <input type="reset" name="btnCancel" id="btnCancel" value="Cancel" /></td>
                              </tr>
                              <tr>
                                <td align="left"></td>
                                <td><label id="loi"></label></td>
                              </tr>
                            </table>
                            
                             <?php
							};
					}else{
        echo("<script>window.location='listnews.php'</script>");
    }
				?>
                </form>
                
                
                     <?php
                     if(isset($_REQUEST["btnSave"])){
						$name = $_REQUEST["txtTitle"];
						$sub = $_REQUEST["txtSubmary"];
						$content = $_REQUEST["txtContent"];
						$pic=$image;
						$comid=$_REQUEST["company"];
						$time=$_REQUEST["date"];
						if($_FILES['file']['name'] != NULL){
										move_uploaded_file($_FILES['file']['tmp_name'],"../images/".$_FILES['file']['name']);
										$fileImage=	$_FILES['file']['name'];
										$pic=$fileImage;
									}else{
										echo "choose file upload";
									}
						$sql = mysql_query("update cars set Name='$name',Sumary='$sub',Content='$content',Image='$pic',TimeProduction='$time',ComID='$comid' where CarID=$id");
						if($sql > 0){
							echo("<script>alert('Update news success.');window.location='listcar.php';</script>");
						}else{
							echo("<script>window.location='loi.php?loi=suacl'</script>");
						}
				}
                ?>
                
                </div>
                <!-- InstanceEndEditable -->
                <!-- // #main -->
                
              <div class="clear"></div>
            </div>
            <!-- // #container -->
        </div>	
        <!-- // #containerHolder -->
        
        <p id="footer">EPROJECT SEM I - APTECH</p>
    </div>
</body>
<!-- InstanceEnd -->